<template>
  <div class="cardMode">
    <div
      class="cardItem"
      v-for="item in list"
      :key="item.id"
      @click="goproTask(item)"
      :style="{
        width: isScreen ? 'calc(100% / 3 - 20px)' : 'calc(25% - 20px)',
      }"
    >
      <span
        :class="['collect', item.followFlag ? 'isCollect' : null]"
        @click.stop="handleCollect(item)"
        ><i class="el-icon-star-off"></i
      ></span>
      <div class="card_bg">
        <div class="card_admin">
          <span>管理员：</span>
          <div>
            <span v-for="val in item.admins" :key="val.id">{{ val.name }}</span>
          </div>
        </div>
        <div class="card_operate">
          <div>
            <span @click.stop="handleOperate('2', item)">编辑</span>
            <span @click.stop="handleOperate('3', item)">详情</span>
            <span @click.stop="handleOperate('4', item)">删除</span>
            <span @click.stop="handleOperate('5', item)">完结</span>
          </div>
        </div>
      </div>
      <div class="card_progress">
        <div
          :style="{
            width: item.progress + '%' || 0,
            background: getColor(item.progress),
          }"
        ></div>
      </div>
      <div class="card_title">
        <img :src="item.avatar" alt="" v-if="item.avatar" />
        <span class="avater" v-else>{{ item.title[0] }}</span
        ><span class="name">{{ item.title }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { collectProApi } from "@/api/task/project.js";
export default {
  props: {
    list: {
      type: Array,
      default: () => {
        [];
      },
    },
    handleOperate: {
      type: Function,
      default: () => {},
    },
    isScreen: {
      type: Boolean,
      default: false,
    },
    goproTask: {
      type: Function,
      default: () => {},
    },
    getList: {
      type: Function,
      default: () => {},
    },
  },
  methods: {
    async handleCollect(val) {
      const res = await collectProApi(val.followFlag ? "2" : "1", val.id);
      if (res.code === 200) {
        this.$message.success(val.followFlag ? "取消收藏成功" : "收藏成功");
        this.getList();
      }
    },
    getColor(val) {
      if (val < 30) {
        return "#f56c6c";
      }
      if (val >= 30 && val < 70) {
        return "#e6a23c";
      }
      if (val >= 70 && val < 100) {
        return "#409eff";
      }
      if (val === 100) {
        return "#67c23a";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.cardMode {
  background: #f0f2f5;
  display: flex;
  flex-wrap: wrap;
  padding-top: 12px;
  .card_bg {
    background: url(../../../../../assets/images/bg2.png) no-repeat;
    background-size: 100% 100%;
    padding-bottom: 12px;
  }
  .cardItem {
    position: relative;
    margin-bottom: 20px;
    background: #fff;
    cursor: pointer;
    width: calc(25% - 20px);
    border-radius: 8px;
    transition: 150ms ease all;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.03);
    margin-right: 20px;
    &:hover {
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      transform: translateY(-5px);
    }
    .collect {
      position: absolute;
      right: 12px;
      top: 12px;
      opacity: 0;
      ::v-deep .el-icon-star-off {
        color: #aaa;
        font-size: 20px;
      }
      &:hover {
        ::v-deep .el-icon-star-off {
          color: #e6a23c;
        }
      }
    }
    &:hover .collect {
      opacity: 1;
    }
    .isCollect {
      ::v-deep .el-icon-star-off {
        color: rgb(248, 166, 42);
        font-size: 20px;
      }
      opacity: 1;
    }
    .card_admin {
      color: #777;
      font-size: 13px;
      padding: 20px 26px;
      display: flex;
      align-items: center;
      width: 100%;
      & > span {
        display: flex;
        flex: 1;
        height: 26px;
        line-height: 26px;
      }
      div {
        margin-right: 6px;
        display: flex;
        align-items: center;
        height: 26px;
        overflow: hidden;
        flex: 5;
        span {
          flex: none;
          line-height: 26px;
          margin-left: 5px;
        }
      }
    }
    &:hover .card_operate div {
      opacity: 1;
    }
    .card_operate {
      display: flex;
      justify-content: center;
      height: 60px;
      align-items: flex-end;
      div {
        font-size: 13px;
        opacity: 0;
        transition: 200ms ease all;
        span {
          margin-right: 16px;
          &:nth-of-type(1) {
            color: #409eff;
          }
          &:nth-of-type(2) {
            color: #e6a23c;
          }
          &:nth-of-type(3) {
            color: #909399;
          }
          &:nth-of-type(4) {
            color: #f56c6c;
          }
          &:nth-of-type(5) {
            color: #67c23a;
          }
        }
      }
    }
    .card_progress {
      div {
        height: 5px;
        background-color: #e6a23c;
        width: 20%;
      }
    }
    .card_title {
      padding: 8px 12px;
      display: flex;
      align-items: center;
      .avater {
        display: inline-block;
        width: 25px;
        height: 25px;
        border-radius: 50%;
        background: #1890ff;
        color: #fff;
        line-height: 25px;
        text-align: center;
        font-size: 16px;
      }
      img {
        width: 25px;
        height: 25px;
        border-radius: 50%;
      }
      .name {
        font-size: 15px;
        font-weight: bold;
        margin-left: 8px;
      }
    }
  }
}
</style>